package com.weiz.designpatterns.memento;

public class Client {
    public static void main(String[] args) {
        // Create originator
        TextEditor textEditor = new TextEditor();
        // Create caretaker
        TextEditorCaretaker caretaker = new TextEditorCaretaker();

        // Add text
        textEditor.appendText("Hello, ");
        System.out.println("Current text: " + textEditor.getText());

        // Save state
        caretaker.saveMemento(textEditor.save());

        // Add more text
        textEditor.appendText("world!");
        System.out.println("Current text: " + textEditor.getText());

        // Restore state
        TextEditorMemento savedMemento = caretaker.getMemento();
        if (savedMemento != null) {
            textEditor.restore(savedMemento);
            System.out.println("Restored text: " + textEditor.getText());
        } else {
            System.out.println("No previous state found.");
        }
    }
}
